package com.ygxsk.carhome.ui.livefee;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.LogUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.gyf.immersionbar.ImmersionBar;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.constant.ConstantSign;
import com.ygxsk.carhome.constant.ExtraKey;
import com.ygxsk.carhome.enumwrap.FeeLiveOtherType;
import com.ygxsk.carhome.ui.ErrorActivity;
import com.ygxsk.carhome.ui.adapter.FeeOtherFragmentAdapter;
import com.ygxsk.carhome.ui.park.ParkManageActivity;
import com.ygxsk.carhome.ui.property.PropertyRepairTransActivity;

import java.util.ArrayList;

import butterknife.BindView;

/*
 * @Author:itchenqi175@163.com
 * @Time:2024/1/5  10:18
 * @Description:添加费用的 其他费用内容
 */
public class FeeOtherActivity extends ErrorActivity {

    //界面的逻辑；
    @BindView(R.id.recyclerviewinfeeliveother)
    RecyclerView recyclerViewInFeeLiveOther;

    private ArrayList<FeeLivingExpensesOtherBean> mDataResources = new ArrayList<>();

    private FeeOtherFragmentAdapter feeOtherFragmentAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mActivityInstance = this;

        initViews();

        gainDatas();

    }

    @Override
    protected void onResume() {
        super.onResume();
//        LogUtils.d(ConstantSign.LOGCAT_NOMAL + mFragmentInstance.getClass().getSimpleName() + "--onResume");
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_fee_other;
    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();

        ImmersionBar.with(this)//
                .titleBar(R.id.toolbarygxskout)
                .fitsSystemWindows(true)//解决状态栏和布局重叠问题，任选其一，默认为false，当为true时一定要指定statusBarColor()，不然状态栏为透明色，还有一些重载方法
                //.statusBarColor(R.color.colorPrimary)//
                //.navigationBarColor(R.color.colorPrimary)//
                //.keyboardEnable(true)
                .init();
    }

    @Override
    protected void initToolBar(ToolbarHelper toolbarHelper) {

        toolbarHelper.setTitle(getString(R.string.title_property_service));

        toolbarHelper.setVersionName(true, AppUtils.getAppVersionName());
        toolbarHelper.setLayoutLeft(true, R.drawable.backicon, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                methodBack();
            }
        });

        toolbarHelper.setLayoutClose(false, "", null);

        //右侧是【编辑】
//        toolbarHelper.setLayoutRight(true, 1, getString(R.string.title_cardverifi_right), new ClickUtils.OnDebouncingClickListener() {
//            @Override
//            public void onDebouncingClick(View v) {
//
//                //携带信息跳转到【编辑-提交】页面；
//                Bundle extra_bundle = new Bundle();
//                //携带是 客户关怀 过去的 到卡券核销列表
//                extra_bundle.putInt(ExtraKey.EXTRA_JUMPFROM_WHERE, ExtraValue.VALUE_JUMP_FORM_CARD_MAIN_ACTIVITY);
//                ActivityUtils.startActivity(extra_bundle, CardDistHistoryActivity.class);
//
//            }
//        });

    }

    @Override
    protected void onClickNodata(View v) {

//        gainDatas();

    }

    @Override
    protected void initViews() {

        //九宫格布局
        recyclerViewInFeeLiveOther.setLayoutManager(new GridLayoutManager(this, 2));

        feeOtherFragmentAdapter = new FeeOtherFragmentAdapter(R.layout.feeotherfragmentadapter, mDataResources);
        recyclerViewInFeeLiveOther.setAdapter(feeOtherFragmentAdapter);
        feeOtherFragmentAdapter.notifyDataSetChanged();

        feeOtherFragmentAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {

                FeeLivingExpensesOtherBean feeLivingExpensesOtherBean = (FeeLivingExpensesOtherBean) adapter.getItem(position);

                if (feeLivingExpensesOtherBean != null) {

                    LogUtils.d(ConstantSign.LOGCAT_NOMAL + "点击-->" + feeLivingExpensesOtherBean.getName());

                    int indexPosition = feeLivingExpensesOtherBean.getIndexPostion();

//        enum FeeLiveOtherType {
//            TYPE_PROPERTY(1, "物业费"),//
//            TYPE_RENTAL(2, "租赁费");//

                    if (indexPosition == FeeLiveOtherType.TYPE_PROPERTY.getIndex()) {

                        //是 物业缴费
                        Bundle bundle_extra = new Bundle();
                        bundle_extra.putInt(ExtraKey.EXTRA_JUMPFROM_WHERE, FeeLiveOtherType.TYPE_PROPERTY.getIndex());

                        ActivityUtils.startActivity(bundle_extra, PropertyPaymentActivity.class);

                    } else if (indexPosition == FeeLiveOtherType.TYPE_RENTAL.getIndex()) {

                        //是租赁费
                        //和物业缴费  接口类似,但是要分开
                        Bundle bundle_extra = new Bundle();
                        bundle_extra.putInt(ExtraKey.EXTRA_JUMPFROM_WHERE, FeeLiveOtherType.TYPE_RENTAL.getIndex());

                        ActivityUtils.startActivity(bundle_extra, PropertyPaymentActivity.class);


                    } else if (indexPosition == FeeLiveOtherType.TYPE_SUBMIT_REPAIR.getIndex()) {

                        // TODO: 2023/12/26 14:06 是物业报修 一级分类入口
                        Bundle bundle_extra = new Bundle();
                        bundle_extra.putInt(ExtraKey.EXTRA_JUMPFROM_WHERE, FeeLiveOtherType.TYPE_SUBMIT_REPAIR.getIndex());

                        ActivityUtils.startActivity(bundle_extra, PropertyRepairTransActivity.class);

                    } else if (indexPosition == FeeLiveOtherType.TYPE_ELECTRIC.getIndex()) {

                        // TODO: 2024/1/5 9:27 电费
                        Bundle bundle_extra = new Bundle();
                        bundle_extra.putInt(ExtraKey.EXTRA_JUMPFROM_WHERE, FeeLiveOtherType.TYPE_ELECTRIC.getIndex());
                        ActivityUtils.startActivity(bundle_extra, FeeElectricActivity.class);

                    } else if (indexPosition == FeeLiveOtherType.TYPE_WATER.getIndex()) {

                        // TODO: 2024/1/5 9:27 水费
                        Bundle bundle_extra = new Bundle();
                        bundle_extra.putInt(ExtraKey.EXTRA_JUMPFROM_WHERE, FeeLiveOtherType.TYPE_WATER.getIndex());
                        ActivityUtils.startActivity(bundle_extra, FeeWaterActivity.class);

                    } else if (indexPosition == FeeLiveOtherType.TYPE_CAR_PLACE.getIndex()) {

                        // TODO: 2024/1/5 9:27 车位管理
                        Bundle bundle_extra = new Bundle();
                        bundle_extra.putInt(ExtraKey.EXTRA_JUMPFROM_WHERE, FeeLiveOtherType.TYPE_CAR_PLACE.getIndex());
                        ActivityUtils.startActivity(bundle_extra, ParkManageActivity.class);

                    }

                }
            }
        });

    }

    @Override
    protected void gainDatas() {

//        enum FeeLiveOtherType {
//                TYPE_PROPERTY(1, "物业费"),//
//                TYPE_RENTAL(2, "租赁费"),
//                TYPE_SUBMIT_REPAIR(3, "物业报修"),
//                TYPE_ELECTRIC(4, "电费"),
//                TYPE_WATER(5, "水费");//

        //写固定的数据
        //电费
        FeeLivingExpensesOtherBean feeLivingExpensesOtherBeanElectric = new FeeLivingExpensesOtherBean();
        feeLivingExpensesOtherBeanElectric.setIndexPostion(FeeLiveOtherType.TYPE_ELECTRIC.getIndex());
        feeLivingExpensesOtherBeanElectric.setName(getString(R.string.title_electric_a));
        feeLivingExpensesOtherBeanElectric.setImageIds(R.drawable.fee_electric);

        //水费
        FeeLivingExpensesOtherBean feeLivingExpensesOtherBeanWater = new FeeLivingExpensesOtherBean();
        feeLivingExpensesOtherBeanWater.setIndexPostion(FeeLiveOtherType.TYPE_WATER.getIndex());
        feeLivingExpensesOtherBeanWater.setName(getString(R.string.title_water_a));
        feeLivingExpensesOtherBeanWater.setImageIds(R.drawable.fee_water);

        //物业费
        FeeLivingExpensesOtherBean feeLivingExpensesOtherBeanStrata = new FeeLivingExpensesOtherBean();
        feeLivingExpensesOtherBeanStrata.setIndexPostion(FeeLiveOtherType.TYPE_PROPERTY.getIndex());
        feeLivingExpensesOtherBeanStrata.setName(getString(R.string.fee_strata));
        feeLivingExpensesOtherBeanStrata.setImageIds(R.drawable.stratafe);

        //租赁费
        FeeLivingExpensesOtherBean feeLivingExpensesOtherBeanRental = new FeeLivingExpensesOtherBean();
        feeLivingExpensesOtherBeanRental.setIndexPostion(FeeLiveOtherType.TYPE_RENTAL.getIndex());
        feeLivingExpensesOtherBeanRental.setName(getString(R.string.fee_rental));
        feeLivingExpensesOtherBeanRental.setImageIds(R.drawable.rentalfe);

        //物业报修
        FeeLivingExpensesOtherBean feeLivingExpensesOtherSubmitRepair = new FeeLivingExpensesOtherBean();
        feeLivingExpensesOtherSubmitRepair.setIndexPostion(FeeLiveOtherType.TYPE_SUBMIT_REPAIR.getIndex());
        feeLivingExpensesOtherSubmitRepair.setName(getString(R.string.fee_submit_repair));
        feeLivingExpensesOtherSubmitRepair.setImageIds(R.drawable.icon_wybx);

        //车位管理或者车位管理费用
        FeeLivingExpensesOtherBean feeLivingExpensesOtherCarPlace = new FeeLivingExpensesOtherBean();
        feeLivingExpensesOtherCarPlace.setIndexPostion(FeeLiveOtherType.TYPE_CAR_PLACE.getIndex());
        feeLivingExpensesOtherCarPlace.setName(getString(R.string.fee_carplace_manager));
        feeLivingExpensesOtherCarPlace.setImageIds(R.drawable.fee_carpla);


        //添加这两条数据
        if (mDataResources != null && !mDataResources.isEmpty()) {
            mDataResources.clear();
        }

        mDataResources.add(feeLivingExpensesOtherBeanElectric);
        mDataResources.add(feeLivingExpensesOtherBeanWater);

        mDataResources.add(feeLivingExpensesOtherBeanStrata);
        mDataResources.add(feeLivingExpensesOtherBeanRental);
        mDataResources.add(feeLivingExpensesOtherSubmitRepair);

        mDataResources.add(feeLivingExpensesOtherCarPlace);

        if (feeOtherFragmentAdapter != null) {
            feeOtherFragmentAdapter.notifyDataSetChanged();
        }


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        if (mDataResources != null && !mDataResources.isEmpty()) {
            mDataResources.clear();
//            mDataResources = null;
        }

        if (feeOtherFragmentAdapter != null) {
            feeOtherFragmentAdapter.notifyDataSetChanged();
            feeOtherFragmentAdapter = null;
        }

        if (mDataResources != null) {
            mDataResources = null;
        }

    }

    @Override
    protected void methodBack() {

        methodBackFinish();
    }
}